package com.example.echoewish.ui.my_activity.my_friend_activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.example.echoewish.pojo.MyConcern;
import com.example.echoewish.R;
import com.example.echoewish.econstant.Constant;
import com.example.echoewish.ui.my_activity.user_info_activity.UserInfoShowActivity;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

public class MyConcernAdapter extends ArrayAdapter<MyConcern> {
    private int resource;
    private Context context;

    private TextView nameTextView;
    private Button cancelFriendButton;
    private Button msgButton;

    private MsgButtonListener msgButtonListener;


    public MyConcernAdapter(@NonNull Context context, int resource, @NonNull List<MyConcern> objects) {
        super(context, resource, objects);
        this.resource=resource;
        this.context=context;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        View view= LayoutInflater.from(context).inflate(resource,parent,false);
        nameTextView=view.findViewById(R.id.my_friend_text_view);
        msgButton=view.findViewById(R.id.my_friend_private_message_button);
        CircleImageView headImageView=view.findViewById(R.id.my_friend_image_view);

        MyConcern myConcern=getItem(position);
        if(myConcern!=null)
        {
            nameTextView.setText(myConcern.name);
            if(myConcern.headImage!=null&&!myConcern.headImage.equals(""))
                Glide.with(context).load(Constant.HEAD_IMAGE_URL+myConcern.headImage).into(headImageView);
            else
                Glide.with(context).load(R.drawable.no_load).into(headImageView);
        }

        headImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                msgButtonListener.headImageClickListener(position);
            }
        });

        msgButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                msgButtonListener.onClickListener(position);
            }
        });
        return view;
    }

    public void setMsgButtonListener( MsgButtonListener msgButtonListener)
    {
        this.msgButtonListener=msgButtonListener;
    }

    public interface MsgButtonListener
    {
        void onClickListener(int position);

        void headImageClickListener(int position);
    }

}